package com.haipi.init;

import java.io.IOException;
import java.util.Iterator;
import java.util.Set;
import java.util.Map.Entry;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.stereotype.Component;

import com.common.constant.Commonality;
import com.common.logger.SysLogger;
import com.haipi.model.CommInitial;

@Component("initializationProperties")
@Scope("singleton")
public class InitializationProperties
{

	@Autowired
	private ResourceLoader resourceLoader = null;

	public ResourceLoader getResourceLoader()
	{
		return resourceLoader;
	}

	public void setResourceLoader(ResourceLoader resourceLoader)
	{
		this.resourceLoader = resourceLoader;
	}

	@PostConstruct
	public void init()
	{
		Resource resource = resourceLoader
				.getResource("classpath:init.properties");
		try
		{
			Commonality.properties.load(resource.getInputStream());

			Set propSet = Commonality.properties.entrySet();

			Iterator<Entry<String, String>> iterator = propSet.iterator();

			while (iterator.hasNext())
			{
				Entry<String, String> entry = iterator.next();
				CommInitial.initialParamMap.put(entry.getKey(), entry
						.getValue());
			}
		} catch (IOException e)
		{
			SysLogger.errorToLog1(e);
		}

	}

}
